import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/components/custom_modele/custom_gradient_line.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/core/utils/file_util.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/modules/application/basic_information/personnel_management/people_information_list/people_information_details/people_information_details_controller.dart';

/// 人员信息详情
class PeopleInformationDetailsPage extends StatelessWidget {
  PeopleInformationDetailsPage({super.key});

  final controller = Get.put(PeopleInformationDetailsController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
      init: controller,
      builder: (controller) {
        return Scaffold(
          appBar: CustomAppBar(titleText: '人员信息详情'),
          body: Container(
              color: const Color(0xffF5F5F6),
              child: SingleChildScrollView(
                  child: Column(
                children: [
                  AppGaps.vGap12,
                  Container(
                    height: 2.w,
                    color: const Color(0xFF587DF5),
                  ),
                  Container(
                    alignment: Alignment.centerLeft,
                    color: const Color(0xFFF4F7FF),
                    padding: EdgeInsets.only(left: 40.w, top: 10.w, bottom: 10.w, right: 20.w),
                    child: Text('姓名:${controller.entity.nickname}',
                        style: TextStyle(
                          fontSize: 16.sp,
                          color: const Color(0xFF262F38),
                        )),
                  ),
                  Container(
                    height: 1.w,
                    color: const Color(0xFFDEE5FD),
                  ),
                  Container(
                    color: const Color(0xFFffffff),
                    padding: EdgeInsets.symmetric(horizontal: 40.w, vertical: 14.w),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        _getTextView(title: '工号：', value: controller.entity.jobNumber!),
                        AppGaps.vGap12,
                        _getTextView(title: '电话：', value: controller.entity.mobile!),
                        AppGaps.vGap12,
                        _getTextView(title: '人员类型：', value: controller.entity.userTypeName!),
                        AppGaps.vGap12,
                        _getTextView(title: '出生日期：', value: controller.entity.birthday!),
                        AppGaps.vGap12,

                        ///	性别: 0.男 1.女 2.保密
                        _getTextView(title: '性别：', value: _stringSex(controller.entity.sex!)),
                        AppGaps.vGap12,
                        _getTextView(title: '岗位名称：', value: controller.entity.positionName!),
                        AppGaps.vGap12,
                        _getTextView(title: '联系电话：', value: controller.entity.mobile!),
                        AppGaps.vGap12,
                        _getTextView(title: '最后毕业院校：', value: controller.entity.school!),
                        AppGaps.vGap12,
                        _getTextView(title: '学历：', value: controller.entity.educationName!),
                        AppGaps.vGap12,
                        _getTextView(title: '职称：', value: controller.entity.titleName!),
                        AppGaps.vGap20,
                        const CustomGradientLine(width: double.infinity),
                        AppGaps.vGap20,
                        _getTextView(title: '是否是主要要负责人：', value: controller.entity.mainPersonInCharge == 1 ? '是' : '否', width: 190.w),
                        AppGaps.vGap12,
                        _getTextView(title: '是否分管安全负责人：', value: controller.entity.branchPersonInCharge == 1 ? '是' : '否', width: 190.w),
                        AppGaps.vGap12,
                        _getTextView(title: '是否专职安全人员：', value: controller.entity.specialitySafe == 1 ? '是' : '否', width: 190.w),
                        AppGaps.vGap12,
                        _getTextView(title: '是否具备化工学历背景：', value: controller.entity.chemistry == 1 ? '是' : '否', width: 190.w),
                        AppGaps.vGap12,
                        _getTextView(title: '是否取得安全工程师资格：', value: controller.entity.safetyEngineer == 1 ? '是' : '否', width: 190.w),
                        AppGaps.vGap20,
                        _getTextView(title: '是否专业技术管理人员：', value: controller.entity.technicalPersonnel == 1 ? '是' : '否', width: 190.w),
                        AppGaps.vGap20,
                        const CustomGradientLine(width: double.infinity),
                        AppGaps.vGap20,
                        _getTextView(title: '证书名称：', value: controller.entity.certificate!, width: 190.w),
                        AppGaps.vGap12,
                        _getTextView(title: '证书编号：', value: controller.entity.certificateNum!, width: 190.w),
                        AppGaps.vGap12,
                        _getTextView(title: '初领时间：', value: controller.entity.firstTime!, width: 190.w),
                        AppGaps.vGap12,
                        _getTextView(title: '证书有效期起：', value: controller.entity.starTime!, width: 190.w),
                        AppGaps.vGap12,
                        _getTextView(title: '证书有效期止：', value: controller.entity.endTime!, width: 190.w),
                        AppGaps.vGap12,
                        _getTextView(title: '证书临期提醒/天：', value: controller.entity.certificateRemind.toString(), width: 190.w),
                        AppGaps.vGap12,
                        Row(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            SizedBox(
                              width: 190.w,
                              child: Text(
                                '文件:',
                                style: TextStyle(
                                  fontSize: 13.sp,
                                  height: 1.2,
                                  fontWeight: FontWeight.w400,
                                  color: const Color(0xff7C7D93),
                                ),
                              ),
                            ),
                            Expanded(
                              child: Column(
                                children: controller.fileList.map(_getAttachmentView).toList(),
                              ),
                            ),
                          ],
                        ),
                      ],
                    ),
                  ),
                ],
              ))),
        );
      },
    );
  }

  /// 获取附件列显示
  Widget _getAttachmentView(String url) {
    //本地文件名
    final String currUrlName = url.toString().substring(25);
    return Container(
      margin: EdgeInsets.only(bottom: 10.w),
      child: Text(
        currUrlName,
        style: TextStyle(
          fontSize: 13.sp,
          color: const Color(0xFF5C6DFF),
        ),
      ).clickOnce(() {
        //打开文件
        FileUtils.openFile(Interface.fileUrl + url);
      }),
    );
  }

  /// 获取字段显示
  Widget _getTextView({required String title, required String value, double? width}) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        SizedBox(
          width: width ?? 110.w,
          child: Text(
            title,
            style: TextStyle(
              fontSize: 13.sp,
              height: 1.2,
              fontWeight: FontWeight.w400,
              color: const Color(0xff7C7D93),
            ),
          ),
        ),
        Expanded(
            child: Text(
          value,
          style: TextStyle(
            fontSize: 14.sp,
            height: 1.2,
            fontWeight: FontWeight.w400,
            color: const Color(0xff495061),
          ),
        ))
      ],
    );
  }

  ///性别: 0.男 1.女 2.保密
  String _stringSex(int i) {
    switch (i) {
      case 0:
        return '男';
      case 1:
        return '女';
      case 2:
        return '保密';
    }
    return '';
  }
}
